package edu.calvin.djs32.cs214.interpreters.calculator.primitives;

import ovm.polyd.PolyD;
import edu.calvin.cs214.hobbes2008.HobbesTIR;
import edu.calvin.cs214.hobbes2008.IntegerTIR;
import edu.calvin.cs214.hobbes2008.StringTIR;
import edu.calvin.djs32.cs214.interpreters.calculator.IPrimitive;

public class AddPrimitive implements IPrimitive, IAddPrimitive{

	public HobbesTIR apply(HobbesTIR... tir) {
		IAddPrimitive dispatcher = PolyD.build(IAddPrimitive.class, this);
		return dispatcher.add(tir[0], tir[1]);
	}

	public HobbesTIR add(IntegerTIR tir1, IntegerTIR tir2) {
		return new IntegerTIR(tir1.getInt() + tir2.getInt());
	}
	
	public HobbesTIR add(IntegerTIR tir1, StringTIR tir2) {
		return new StringTIR(tir1.toString() + tir2.getString());
	}

	public HobbesTIR add(StringTIR tir1, StringTIR tir2) {
		return new StringTIR(tir1.getString() + tir2.getString());
	}
	
	public HobbesTIR add(StringTIR tir1, IntegerTIR tir2) {
		return new StringTIR(tir1.getString() + tir2.toString());
	}

	public HobbesTIR add(HobbesTIR tir1, HobbesTIR tir2) {
		throw new IllegalStateException("unimplemented!");
	}


}
